package threadpool;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Classname ShutDown
 * @Description 关闭线程池
 * @Date 2024/1/7 20:40
 * @Author zhuzhenguo
 */
public class ShutDown {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new ShutDownTask());
        }
        Thread.sleep(1500);
//        List<Runnable> runnableList = executorService.shutdownNow();

        System.out.println(executorService.isShutdown());
        System.out.println(executorService.isTerminated());

        executorService.shutdown();

        System.out.println(executorService.isShutdown());
        Thread.sleep(10000);
        System.out.println(executorService.isTerminated());
        // 已经停止了，再提交任务是提交不了的
        executorService.execute(new ShutDownTask());
        // 会阻塞 等待线程池中线程执行完毕
        boolean b = executorService.awaitTermination(7L, TimeUnit.SECONDS);
        System.out.println(b);
//        System.out.println(executorService.isTerminated());

//        executorService.execute(new ShutDownTask());
    }

}
